package com.bangcommunity.bbframe.mlog.collector;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author tanghc
 * @date 18/1/30
 */
public abstract class ConcurrentCountHelper {
    private static final ConcurrentMap<String, AtomicLong> concurrents = new ConcurrentHashMap<>();

    /**
     * 获取并发计数器
     */
    public static AtomicLong getConcurrent(String key) {
        AtomicLong concurrent = concurrents.get(key);
        if (concurrent == null) {
            concurrents.putIfAbsent(key, new AtomicLong());
            concurrent = concurrents.get(key);
        }
        return concurrent;
    }

}
